home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * main.c for CDEF shell
- *
- * Copyright © 1990 Michael S. Engber. All rights reserved
- */
-
- /*
- * Thanks to:
- * Steve Hawley
- * Whose CDEF button source I used as an example. His source was
- * squirreled away in my archives & I can't recall how I got it.
- * Off the INTERNET I'm sure.
- * Jean deCombret
- * Whose Jan '89 MacTutor article explained the "clean way" to
- * install a procedure as a fake CDEF.
- */
-
- #include "pup.h"
-
- #define WINDOW_ID 100
- #define JMP_INST 0x4EF9
-
- typedef struct{
- short jmpInst;
- ProcPtr addrCDEF;
- }fakeCDEF,*fakeCDEF_p,**fakeCDEF_h;
-
- static fakeCDEF_h installCDEF(int idCDEF){
- fakeCDEF_h fakeH = (fakeCDEF_h)Get1Resource('CDEF',idCDEF);
- (*fakeH)->jmpInst = JMP_INST;
- (*fakeH)->addrCDEF = (ProcPtr)&mainCDEF;
- return fakeH;
- }
-
- main ()
- {
- fakeCDEF_h fakeH;
-
- Rect r = {20, 30, 40, 260};
-
- ControlHandle fontPup;
- ControlHandle resMenuPup;
-
- WindowPtr mainWindow;
-
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
-
- FlushEvents(everyEvent,0);
- InitCursor();
-
- mainWindow = GetNewWindow(WINDOW_ID,0L,(WindowPtr)(-1L));
- SetPort(mainWindow);
-
- fakeH = installCDEF(PUP_ID);
-
- fontPup = NewControl(
- mainWindow, /* window to contain the pup */
- &r, /* contrlRect */
- "\pfont pup:", /* contrlTitle - used as pop-up title */
- true, /* make it visible */
- 1, /* cntrlValue - selected item */
- 0, /* cntrlMin - make up a menu id */
- 120, /* cntrlMax - width of pop-up title box */
- 16 * PUP_ID, /* control definition ID */
- 'FONT' /* refCon - add fonts items */
- );
-
- OffsetRect(&r,0,25);
-
- resMenuPup = NewControl(
- mainWindow, /* window to contain the pup */
- &r, /* contrlRect */
- "\p", /* contrlTitle - menu title is used */
- true, /* make it visible */
- 3, /* cntrlValue - selected item */
- 100, /* cntrlMin - use menu with rsrc id 100 */
- 120, /* cntrlMax - width of pop-up title box */
- 16 * PUP_ID, /* control definition ID */
- 0L /* refCon - don't add any rsrc items */
- );
-
-
- while(1) {
- EventRecord curEvent;
- ControlHandle curControl;
-
- if(GetNextEvent(everyEvent, &curEvent)){
- if(curEvent.what == keyDown) ExitToShell();
- if(curEvent.what == mouseDown){
- GlobalToLocal(&curEvent.where);
- if(FindControl(curEvent.where, mainWindow, &curControl))
- TrackControl(curControl, curEvent.where, 0L);
- }
- }
- }
- }
-